package com.patrol.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.patrol.pojo.SendInfo;
import com.patrol.pojo.Worker;
import com.patrol.pojo.Xglx;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface WorkDao extends BaseMapper<Worker> {

//    @Insert("insert into worker (user_id,start_time,working) values(#{userId},#{date},1")
//    int signWork(int userId, String date);

    @Select("select * from worker")
    List<Worker> selectAllWorkers();

    @Insert("insert into user_clock (userId,time) values(#{userId},#{time})")
    void userClock(int userId,String time);

    @Select("select id from user_clock where userId=#{userId} and time=#{time}")
    Integer findUserClock(Integer userId, String time);

    @Select("select time from user_clock where userId=#{userId}")
    List<String> findHistoryUserClock(Integer userId);

    @Insert("insert into worker (user_id,task_num,not_num,sign) values(#{userId},0,0,0)")
    void createUserTask(Integer userId);

    @Update("update worker set task_num=task_num+1,not_num=not_num+1 where user_id=#{userId} and sign=0")
    void updateUserTaskNum(Integer userId);

    @Select("select id from worker where user_id=#{userId}")
    int selectNowUserRWId(int userId);

    @Update("update worker set not_num=not_num-1 where id=#{rwId}")
    void updateNotNumByRWId(int rwId);

    @Update("update worker set sign=1 where user_id=#{userId}")
    void updateTaskSign(Integer userId);

    @Select("select * from send_info where user_id=#{userId}")
    List<SendInfo> selectInfo(Integer userId);

    @Select("select user_id from xglx where sign=0")
    List<Integer> selectNowXGUser();

    @Insert("insert into xglx (user_id,start_time,sign) values(#{userId},#{startTime},0)")
    void insertXGLX(Integer userId, String startTime);

    @Update("update xglx set over_time=#{overTime} where id=#{id}")
    void insertXGLXOverTime(String overTime, Integer id);

    @Select("select start_time from xglx where sign=0 and user_id=#{userId}")
    String selectStartTime(Integer userId);

    @Select("select id from xglx where sign=0 and user_id=#{userId}")
    Integer selectXGLXId(Integer userId);

    @Update("update xglx set sign=1 where user_id=#{userId}")
    void updateXGLXSign(Integer userId);

    @Select("select over_time from worker where user_id=#{userId} and sign=0")
    String selectRWOverTime(Integer userId);

    @Select("select * from xglx where user_id=#{userId} and sign=0")
    List<Xglx> selectAllInRW(int userId);

    @Select("select * from xglx where user_id=#{userId}")
    List<Xglx> selectXGHistory(int userId);

    @Select("select * from xgexport where time in (#{startTime},#{endTime})")
    List XGUserNumExport(String startTime, String endTime);

    @Insert("insert into xgexport (xgzs,dgzs,time) values(#{xgzs},#{dgzs},#{time})")
    void addXGTJ(int xgzs,int dgzs,String time);

    @Update("update xgexport set dgzs=#{dgzs} where id=#{id}")
    void updateXGTJ(int id,int dgzs);

    @Select("select id from xgexport where time=#{time}")
    Integer selectXGExport(String time);

    @Select("select count(*) from task_point")
    int selectRWNum();

    @Select("select sum(not_num) from worker")
    int selectRWLCNum();

    @Insert("insert into rwexport (rwnum,lcnum,time,hfxnum,zfxnum,dfxnum) values(#{rwNum},#{rwlcNum},#{time},#{hfxnum},#{zfxnum},#{dfxnum})")
    void addRWTJ(int rwNum, int rwlcNum, String time, int hfxnum, int zfxnum, int dfxnum);

    @Update("update rwexport set lcnum=#{rwlcNum},hfxnum=#{hfxnum},zfxnum=#{zfxnum},dfxnum=#{dfxnum} where id=#{id}")
    void updateRWTJ(Integer id, int rwlcNum, int hfxnum, int zfxnum, int dfxnum);

    @Select("select id from rwexport where time=#{time}")
    Integer selectRWReport(String time);

    @Select("select count(*) from risk_point where status=0")
    int selectHfxNum();

    @Select("select count(*) from risk_point where status=1")
    int selectZfxNum();

    @Select("select count(*) from risk_point where status=2")
    int selectDfxNum();

    @Insert("insert into userkq (userId,name,dkTime,detailTime) values(#{userId},#{realName},#{time},#{detailTime})")
    void addUserKQTJ(int userId, String realName, String time, String detailTime);

    @Select("select sum(not_num) from worker where sign=1 and user_id=#{userId}")
    int selectRWLCNumById(Integer userId);

    @Update("update userkq set lcnum=#{num} where userId=#{userId}")
    void updateUserKQTJ(int num, int userId);

    @Select("select count(id) from user_clock where time=#{time}")
    int selectDGNum(String time);

    @Select("select id from userkq where userId=#{userId} and dkTime=#{dkTime}")
    Integer selectUserToday(Integer userId, String dkTime);
}
